package com.woniuxy.dr_mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.dr_mall.entity.DrRealSpecEntry;
import com.woniuxy.dr_mall.entity.DrSpecPrice;
import com.woniuxy.dr_mall.entity.DrSpecVO;
import com.woniuxy.dr_mall.entity.DrVSku;
import com.woniuxy.dr_mall.mapper.DrSpecPriceMapper;
import com.woniuxy.dr_mall.mapper.DrSpecValMapper;
import com.woniuxy.dr_mall.mapper.DrVSkuMapper;
import com.woniuxy.dr_mall.service.IDrSpecPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
@Service
public class DrSpecPriceServiceImpl extends ServiceImpl<DrSpecPriceMapper, DrSpecPrice> implements IDrSpecPriceService {

    @Autowired
    private DrSpecPriceMapper specPriceMapper;
    @Autowired
    private DrVSkuMapper vSkuMapper;
    @Autowired
    private DrSpecValMapper specValMapper;
    @Override
    public List<DrSpecPrice> getPriceByPid(int pid) {
        return specPriceMapper.getPriceByPid(pid);
    }
    @Override
    public List<DrSpecPrice> getSkus(DrSpecVO specVO) {
        return specPriceMapper.getSkus(specVO);
    }
    @Override
    public DrSpecPrice getSkuBySkuId(Integer skuId) {
        return specPriceMapper.getSkusBySkuId(skuId);
    }

    @Override
    public List<DrVSku> getAllVSku() {
        List<DrVSku> skus = vSkuMapper.getAllSkus();
        for (DrVSku sku : skus) {
            List<DrRealSpecEntry> specEntries = new ArrayList<>();
            if(sku.getMaterial()!=null){
                DrRealSpecEntry specEntry = new DrRealSpecEntry();
                specEntry.setSpecName("材质");
                specEntry.setValName(specValMapper.selectById(sku.getMaterial()).getSpecVal());
                specEntries.add(specEntry);
            }
            if(sku.getColor()!=null){
                DrRealSpecEntry specEntry = new DrRealSpecEntry();
                specEntry.setSpecName("颜色");
                specEntry.setValName(specValMapper.selectById(sku.getColor()).getSpecVal());
                specEntries.add(specEntry);
            }
            if(sku.getType()!=null){
                DrRealSpecEntry specEntry = new DrRealSpecEntry();
                specEntry.setSpecName("款式");
                specEntry.setValName(specValMapper.selectById(sku.getType()).getSpecVal());
                specEntries.add(specEntry);
            }
            if(sku.getSize()!=null){
                DrRealSpecEntry specEntry = new DrRealSpecEntry();
                specEntry.setSpecName("尺寸");
                specEntry.setValName(specValMapper.selectById(sku.getSize()).getSpecVal());
                specEntries.add(specEntry);
            }
            if(sku.getSeries()!=null){
                DrRealSpecEntry specEntry = new DrRealSpecEntry();
                specEntry.setSpecName("系列");
                specEntry.setValName(specValMapper.selectById(sku.getSeries()).getSpecVal());
                specEntries.add(specEntry);
            }
            if(sku.getWeight()!=null){
                DrRealSpecEntry specEntry = new DrRealSpecEntry();
                specEntry.setSpecName("重量");
                specEntry.setValName(specValMapper.selectById(sku.getWeight()).getSpecVal());
                specEntries.add(specEntry);
            }
            sku.setSpecEntries(specEntries);
        }
        return skus;
    }
}
